<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            background: #000;
            color: #fff;
            font-size: 50px;
            padding-top: 100px;
            text-align: center;
        }
    </style>
</head>

<body>
    <h1></h1>
    <script>

        const h1 = document.querySelector('h1')
        setInterval(() => {
            h1.innerHTML = getFullDay(new Date())
        }, 1000)
        // let date = new Date(2022,7,12);
        // console.log(date.getDay());
        // 星期
        function getWeek(date) {
            // date.getDay()
            // if (date.getDay() == 0) {
            //     return '星期日'
            // }else if(date.getDay() == 1){
            //     return '星期一'
            // }

            // switch (date.getDay()){
            //     case 0:
            //         return '星期日'
            //     case 1:
            //         return '星期一'
            //     case 2:
            //         return '星期二'
            //     case 3:
            //         return '星期三'
            //     case 4:
            //         return '星期四'
            //     case 5:
            //         return '星期五'
            //     case 6:
            //         return '星期六'
            // }

            const arr = ["日", "一", "二", "三", "四", "五", "六"]
            return '星期' + arr[date.getDay()]
        }

        console.log(getWeek(new Date(2022,6,10)));



        function addZero(num) {
            return num < 10 ? '0' + num : num + ''
        }
        console.log(addZero('2'));
        console.log(addZero(12));

        function isLeapYear(year) {
            if (year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0)) {
                return true
            } else {
                return false
            }
        }
        // 年
        function getYear(date) {
            return date.getFullYear()
        }
        console.log(getYear(new Date()));
        // 月
        function getMonth(date) {
            return date.getMonth() +1
        }
        console.log(getMonth(new Date()));
        // 日
        function getDate(date) {
            return date.getDate()
        }
        console.log(getDate(new Date()));
        // 小时
        function getHour(date) {
            return date.getHours()
        }
        console.log(getHour(new Date()));
        // 分钟
        function getMinute(date) {
            return date.getMinutes()
        }
        console.log(getMinute(new Date()));
        //秒
        function getSecond(date) {
            return date.getSeconds()
        }
        console.log(getSecond(new Date()));

        // 毫秒
        function getMillisecond(date) {
            return date.getMilliseconds()
        }
        console.log(getMillisecond(new Date()));



        function getFullDay(date) {
            return `${getYear(date)}年 ${addZero(getMonth(date))}月${addZero(getDate(date))}日 ${getWeek(date)} ${addZero(getHour(date))}:${addZero(getMinute(date))}:${addZero(getSecond(date))}`
        }
        console.log(getFullDay(new Date(2022, 6, 6, 6, 6, 6, 6)));
    </script>
</body>

</html>